const util = require('../../../util/util.js')
Page({
  // onShareAppMessage() {
  //   return {
  //     title: 'tabs',
  //     path: 'page/weui/example/tabs/tabs'
  //   }
  // },
  data: {
    columns: [{
      key: 'ROADNAME',
      title: '道路名称',
      width: 40,
      fixed: 'left',
      align: 'center'
    }, {
      key: 'INFO',
      title: '累计作业长度（作业率）',
      width: 100,
    // }, {
    //   key: '道路总长',
    //   title: '道路总长',
    //   width: 100,
    //   fixed: 'left'
    // }, {
    //   key: 'aa',
    //   title: '作业率',
    //   width: 90
    }],
    dataTask1: [],
    dataTask2: [],
    dataTask3: [],
    dataUnTask1: [],
    dataUnTask2: [],
    dataUnTask3: [],
    tabs: [{
      title: '主干',
    },
    {
      title: '次干',
    },
    {
      title: '支路',
    }],
    activeTab: 0,
    isWork: 0,
  },
  onLoad: function (options) {
    this.setData({
      isWork: options.isWork
    })
    this.GetWorkRoad(this.data.tabs[this.data.activeTab].title)
  },
  // 获取
  GetWorkRoad(typeRoad) {
    var that = this;
    const currentDate = new Date();
    currentDate.setDate(currentDate.getDate() - 1);
    var strURL = 'GetWorkRoadInfoAPP';
    if (this.data.isWork === '0') {
      strURL = 'GetWorkNoRoadInfoAPP'
    }
    wx.request({
      url: 'https://www.ejingyou.cn/ServerHuanwei/CompanyapiBDEapi/Vehicle/' + strURL,
      data: {
        ClientNo: wx.getStorageSync("CLIENT_NO"),
        RType: typeRoad,
        Date: util.formatDateTime(currentDate, true),
      },
      header: {
        'content-type': 'application/json' // 默认值     
      },
      success: (res) => {
        res.data.shift();
        that.setData({
          dataTable: res.data
        });
      }
    })
  },
  // table 方法
  onRowClick (e) {
    console.log('单击列表行')
    console.log(e)
  },
  // tab 方法
  onTabClick(e) {
    this.setData({
      dataTable: []
    });
    const index = e.detail.index
    this.setData({ 
      activeTab: index 
    })
    this.GetWorkRoad(this.data.tabs[index].title)
  },
  handleClick(e) {
    console.log('tab?')
    // wx.navigateTo({
    //   url: './webview',
    // })
  }
})
